CREATE TABLE WFDefinitions
(
	PK_ID			int identity not null primary key,
	HandlerCodeID	nvarchar(50) not null,
	DefName			nvarchar(500) not null
);

[GO]

CREATE TABLE WFProcess
(
	PK_ID			int identity not null primary key,
	FK_DefinitionID	int not null,
	ProcessName		nvarchar(500) not null,
	ProcessType		int not null,
	DataCanView		bit not null,
	DataCanEdit		bit not null,
	Rank			int not null
);

[GO]

CREATE TABLE WFProcessStart
(
	PK_ID			int identity not null primary key,
	FK_ProcessID	int not null,
	Rank			int not null,
	Method			nvarchar(500) not null,
	PropertyBag		ntext not null
)

[GO]

CREATE TABLE WFTasking
(
	PK_ID				int identity not null primary key,
	FK_ProcessID		int not null,
	TaskCaption			nvarchar(500) not null,
	CSV_OperatorID		nvarchar(500),
	CSV_GroupID			nvarchar(500),
	GetUserMethod		nvarchar(500),
	SystemTask			bit,
	SystemExitAt		int,
	SystemExitAtUnit	int,
	ActivateTaskAt		int,
	ActivateTaskAtUnit	int,
	DeadlineTaskAt		int,
	DeadlineTaskAtUnit	int
);

[GO]

CREATE TABLE WFTaskExitPaths
(
	PK_ID				int identity not null primary key,
	FK_TaskingID		int not null,
	Caption				nvarchar(100) not null,
	uiTaskMethod		nvarchar(500) not null,
	CSV_AllowedGroups	nvarchar(500)
);

[GO]

CREATE TABLE WFExitActions
(
	PK_ID				int identity not null primary key,
	FK_ExitPathID		int not null,
	Rank				int not null,
	Method				nvarchar(500) not null,
	PropertyBag			ntext not null
);

[GO]

CREATE TABLE WFTasks
(
	PK_ID					int identity not null primary key,
	HandlerCodeID			nvarchar(50) not null,
	FK_DefinitionID			int not null,
	FK_ProcessID			int not null,
	FK_TaskingID			int not null,
	FK_ForOperatorID		int,
	FK_ForOperatorGroupID	int,
	ForSystem				bit,
	ForSystemExecDT			datetime,
	StartDT					datetime,
	DueDT					datetime,
	TaskCaption				nvarchar(500) not null,
	DataItemText			nvarchar(1000) not null,
	FK_DataID				int
);
